#include <iostream>
#include <csignal>
#include <unistd.h>
#include <cstdlib>
#include <vector>
#include <functional>

// 输入操作
void Input(){
	std::cout<<"启用输入操作"<<std::endl;
}

// 输出操作
void Output(){
	std::cout<<"启用输出操作"<<std::endl;
}

// 运算操作
void Calculation(){
	std::cout<<"启用运算操作"<<std::endl;
}

std::vector<std::function<void()>> operations;
int size = 0;

void signalhandler(int signum){
	if(size < operations.size()){
		operations[size++]();
	} 
	else {
		std::cout << "操作已完成，等待下一次操作。" << std::endl;
		size = 0;
	}
	alarm(1);
}

int main(){
	operations.push_back(Input);
	operations.push_back(Output);
	operations.push_back(Calculation);

	signal(SIGALRM, signalhandler);

	// 调用第一次时钟
	alarm(1);
	
	while(true){
		pause();
	}

	return 0;
}